package battle 
{
	import Common.GameDefine;
	
	import battle.BattleData;
	/**
	 * ...
	 * @author 
	 */
	public class BattleHandlerResult extends BattleHandlerInterface
	{
		
		private var action:BattleResultAction = null;
		private var actionHandler:BattleHandlerResultAction = null;
		
		
		public function BattleHandlerResult() 
		{
			
		}
		
		override public function clear():void 
		{
			action = null;
			
			if ( actionHandler )
				actionHandler.clear();
			
			super.clear();
		}
		
		override public function init():void 
		{
			super.init();
		}
		
		override public function active():void 
		{
			nextAction();
			
			//actionHandler.active();
		}
		
		public function nextAction( b:Boolean = false ):int
		{
			if ( BattleData.instance.battleResultCommand.action.length == 0 ) 
			{
				if ( BattleData.instance.battleResultCommand.result != BattleResultCommand.BATTLENEXT ) 
				{
					BattleSession.instance.setState( BattleState.OVER , b );
					
					return BattleState.OVER;
				}
				
				BattleSession.instance.setState( BattleState.COMMAND );
				
				return BattleState.READY;
			}
			
			actionHandler = null;
			actionHandler = new BattleHandlerResultAction();
			actionHandler.init( nextAction );
			
			action = BattleData.instance.battleResultCommand.action[ 0 ];
			BattleData.instance.battleResultCommand.action.shift();
			
			if ( BattleData.instance.battleResultCommand.result != BattleResultCommand.BATTLENEXT )
			{
				actionHandler.LastAction = true;
			}
			
			actionHandler.setActionCreature( action , 0 );
			actionHandler.active();
			
			return GameDefine.INVALIDID;
		}
		
		
		public function doResult():void
		{
//			for ( var i:int = 0; i < data.battleResultCommand.num ; i++ ) 
//			{
//				var action:BattleResultAction = data.battleResultCommand.action[ i ];
//				
//				switch ( action.type ) 
//				{
//					case BattleCommand.ATTACK:
//						{
//							for ( var j:int = 0; j < action.targetNum; j++ ) 
//							{
//								var target:int = action.target[j];
//							}
//						}
//					break;
//					case BattleCommand.DEFENCE:
//						{
//							
//						}
//					break;
//				}
//			}
		}
		
	}

}